class Solution {
    public:
        vector<int> path;
        vector<vector<int>> ret;
        int distance;
        vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
            distance = target;
            dfs(0,candidates);
            return ret;
        }
        void dfs(int pos,vector<int>& nums){
            // for(auto x : path) cout<<x;
            // cout<<endl;
            if(distance < 0)    return;
            if(distance == 0){
                ret.push_back(path);
                return;
            }    
            for(int i = pos; i < nums.size(); i++){
                distance -= nums[i];
                path.push_back(nums[i]);
                dfs(i,nums);
                distance += nums[i];
                path.pop_back();
            }
        }
    };